<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学员信息修改</title>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../css/okadmin.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>学员信息修改</legend>
</fieldset>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">I&#12288;&#12288;&#12288;D</label>
                        <div class="layui-input-block ">
                            <input type="text" id="studentId" name="studentId"
                                   style="background-color: #dcdcdc" disabled
                                   placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">姓&#12288;&#12288;名</label>
                        <div class="layui-input-block ">
                            <input id="fullname" name="fullname" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder=""  autocomplete="off">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">电&#12288;&#12288;话</label>
                        <div class="layui-input-block ">
                            <input id="phone" name="phone" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">性&#12288;&#12288;别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="agender" id="agender0" value="0" title="女" checked>
                            <input type="radio" name="agender" id="agender1" value="1" title="男">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">邮&#12288;&#12288;箱</label>
                        <div class="layui-input-block ">
                            <input id="email" name="email" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder=""  autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">教&#12288;&#12288;练</label>
                        <div class="layui-input-block ">
                            <select name="coachs" id="coachs" style="float: left;position: relative;" lay-search>
                                <option value="">无需教练</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6" style="float: right;margin-right: 10%">
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" lay-submit id="update">
                            更改
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/jquery.min.js"></script>
<script src="../../js/application.js"></script>
<script>

    var studyStatus=""
    var choiceId=""
    function init(){
        htmlSetValue("studentId")
        htmlSetValue("fullname")
        htmlSetValue("phone")
        htmlSetValue("agender",function(value){
            if(value=="false"){
                $("#agender0").prop('checked',true);
            }else{
                $("#agender1").prop('checked',true);
            }
        })
        htmlSetValue("studyStatus",function(value){
            studyStatus=value;
        })
        htmlSetValue("choiceId",function(value){
            choiceId=value;
        })
        htmlSetValue("email")

    }
    layui.use(['form','layer'], function () {
        var form = layui.form
        var layer = layui.layer
        init()
        form.render();
        myAjax(mainUri + '/coach/selects', {page: -1,studyStatus:studyStatus,isStartChoice:1,teachingStage:studyStatus}, function (datas) {
            var list = datas['data'];
            var option;
            for (var i = 0; i < list.length; i++) {
                {
                    option += "<option value='" + list[i]['coachId'] + "'>" + list[i]['fullname'] + "</option>";
                }
            }
            $("#coachs").append(option);
            htmlSetValue("coachId",function(d){
                if(d){
                    var value="option[value="+d+"]";
                    $("#coachs").find(value).attr('selected',true)
                }
            });
            form.render('select');
        })
        $("#update").on('click',function(){
            var coach = $("#coachs").find("option:checked");
            var msg="确定修改id为 "+$('#studentId').val()+"的学员的信息?";
            var data={studentId:$('#studentId').val(),fullname:$('#fullname').val(),phone:$('#phone').val(),
                agender:$('input[name="agender"]:checked').val(),email:$('#email').val(),studyStatus:studyStatus};
            if(studyStatus=='1'||studyStatus=='4'){
                if(coach.val()){
                    msg+="</br><span style='color: red;font-size: smaller'>科目一,科目四不需要选择教练</span>"
                }
            }else{
                if(choiceId){
                    coach.val()?data["coachId"]=coach.val():""
                    data["choiceId"]=choiceId;
                }
            }
            layer.confirm(msg, function (index) {
                if(choiceId==""&&coach.val()){
                    if (confirm("当前修改的学员未进行教练自选,确定为其分配教练")){
                        coach.val()?data["coachId"]=coach.val():"";
                    }else{
                        return
                    }
                }
                myAjax(mainUri+"/student/update",data,function(d){
                    if(d['code']=='0'){
                        layer.msg(d['msg'], {
                            icon: 1, time: 2000, end: function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index);
                            }
                        })
                    }else{
                        alert(d['msg'])
                    }
                })
            });
        })
    });
</script>
</html>